<template>
  <div class="content_card">
    <UHeader>
      <template slot="left">
        <el-input
          v-model="searchParams.carDriverName"
          size="small"
          clearable
          style="width: 200px"
          placeholder="请输入内容"
          @clear="searchParams = Object.assign({}, searchParams, searchParams)">
          <i slot="prefix" class="el-input__icon el-icon-search"/>
        </el-input>
        <el-button size="mini" type="success" style="margin-right: 15px;margin-left: 15px" @click="searchParams = Object.assign({}, searchParams, searchParams)" >查询</el-button>
        <StatusTab :datas="statusData" :select.sync="searchParams.workstatus" @onChange="searchParams = Object.assign({}, searchParams, searchParams)" />
      </template>
    </UHeader>
    <UTable ref="mTable" :search-api="search"  :columns="columns" :search-params="searchParams" @onHandleClick="onHandleClick" />
  </div>

</template>
<script>
import UHeader from '@/components/UHeader'
import UTable from '@/components/UTable'
import StatusTab from '@/components/StatusTab'
import { search, doExamineCarDriver, doSwitchCarDriverUse } from '@/api/driver'
import columns from './columns'
export default {
  components: {
    UTable, UHeader, StatusTab
  },
  data() {
    return {
      statusData: [{ value: '', label: '全部' }, { value: '0', label: '开工' }, { value: '1', label: '忙碌' }, { value: '2', label: '收工' }],
      search: search,
      searchParams: {
        carDriverName: '',
        workstatus: ''
      },
      columns: columns
    }
  },
  methods: {
    onHandleClick(butIndex, row, rowIndex) {
      if (butIndex === 1 || butIndex === 2) {
        doSwitchCarDriverUse(row.id).then(res => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.mTable.refresh()
        })
      } else if (butIndex === 3 || butIndex === 4) {
        doExamineCarDriver(row.id, butIndex === 3 ? 1 : 0).then(res => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.mTable.refresh()
        })
      }
    }
  }
}
</script>

<style scoped>
  .el-table .error-row {
    background: oldlace;
  }
</style>
